<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
if ( ! function_exists('date_to_mysql'))
{
	function date_to_mysql($year, $month, $day)
	{
		return date("Y-m-d", mktime(0, 0, 0, $month, $day, $year));
	}
}

if ( ! function_exists('time_to_mysql'))
{
	function time_to_mysql($hours, $minutes)
	{
		return date("H:i:s", mktime($hours, $minutes, 0));
	}
}

if ( ! function_exists('unix_to_time'))
{
	function unix_to_time($unixtime)
	{
		return date("g:i a", $unixtime);
	}
}

if ( ! function_exists('encrypt_password'))
{
	function encrypt_password($password)
	{
		return md5($password);
	}
}

if ( ! function_exists('pre_print_r'))
{
	function pre_print_r($object)
	{
		echo "<pre>";
                print_r($object);
                echo "</pre>";
	}
}

if ( ! function_exists('get_role'))
{
	function get_role($role)
	{
            switch($role){
                case(1): return "Restricted Staff";
                case(2): return "Head Staff";
                case(3): return "Administrator";
                default: return "Pleb";
            }
	}
}

if ( ! function_exists('get_role_short'))
{
	function get_role_short($role)
	{
            switch($role){
                case(1): return "rstr";
                case(2): return "head";
                case(3): return "admin";
                default: return "pleb";
            }
	}
}

if ( ! function_exists('get_role_num'))
{
	function get_role_num()
	{
            $ci =& get_instance();
            return $ci->session->userdata('role');
	}
}

if ( ! function_exists('admin_role'))
{
	function admin_role()
	{
            return 3;
	}
}


if ( ! function_exists('filter_profanity'))
{
    function filter_profanity($ToFilter){
       
       $RepChar = ""; 
       $Foul = @file("application/helpers/foul.txt");
       foreach ($Foul as $FoulWord){
          $FoulWord = trim($FoulWord);
          if (@preg_match("/".$FoulWord."/i", $ToFilter)){
             $WordLength = strlen($FoulWord); 
             for ($i = 1; $i <= $WordLength; $i++){
                $RepChar .= "*"; 
             }
             
             $ToFilter = @eregi_replace($FoulWord, $RepChar, trim($ToFilter)); 
             $RepChar = ""; 
          } 
       }
       return $ToFilter; 
    }
}

if (! function_exists('generate_password'))
{
    function generate_password($length=9, $strength=0) {
	$vowels = 'aeuy';
	$consonants = 'bdghjmnpqrstvz';
	if ($strength & 1) {
		$consonants .= 'BDGHJLMNPQRSTVWXZ';
	}
	if ($strength & 2) {
		$vowels .= "AEUY";
	}
	if ($strength & 4) {
		$consonants .= '23456789';
	}
	if ($strength & 8) {
		$consonants .= '@#$%';
	}
 
	$password = '';
	$alt = time() % 2;
	for ($i = 0; $i < $length; $i++) {
		if ($alt == 1) {
			$password .= $consonants[(rand() % strlen($consonants))];
			$alt = 0;
		} else {
			$password .= $vowels[(rand() % strlen($vowels))];
			$alt = 1;
		}
	}
	return $password;
    }
}

if ( ! function_exists('send_email_advanced'))
{
    function send_email_advanced($to, $subject, $message){
        
        $headers =  'From: webmaster@rmplanner.net'. "\r\n";
        $headers .= 'Reply-To: noreply@rmplanner.net' . "\r\n";
        $headers .= 'X-Mailer: PHP/' . phpversion();

        @mail($to, $subject, $message, $headers);
    }
}